package tgc.edu.yzy.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.edu.yzy.entity.Test02;
import tgc.edu.yzy.service.Test01Service;
import tgc.edu.yzy.service.Test02Service;
import tgc.edu.yzy.service.TestService;

@Controller
@RequestMapping(value="/com")
public class ComboboxController {
	@Autowired
	private TestService test;
	@Autowired
	private Test01Service test01;
	@Autowired
	private Test02Service test02;
	
	@RequestMapping(value="/test01")
	@ResponseBody
	private Object test01() {
		return test01.findAll();
	}
	
	@RequestMapping(value="/test02")
	@ResponseBody
	private Object test02(Integer id) {
		List<Test02> test=test02.findByParentId(id);
		return test;
	}
	/***
	 * 自动搜索的方法
	 * @return
	 */
	@RequestMapping(value="/test03")
	@ResponseBody
	private Object test03(String q) {
		if(q==""||q==null) {
			String sql="%";
			sql=sql+q+"%";
			List<Test02> te=test02.findLike(sql);
			return te;
		}else {
			q=q.trim();
			String sql="%";
			sql=sql+q+"%";
			List<Test02> te=test02.findLike(sql);
			return te;
					
		}
	}
}
